package com.hframe.plugin.wechat;

import com.hframe.Json.JsonFiletr;
import com.hframe.data.DRef;
import com.hframe.type.TEnum;
import com.hframe.type.TString;
import com.hframe.typefilter.FilterRef;
import org.apache.log4j.Logger;

/**
 * 微信接口请求返回结果
 * Created by heqian on 17-9-19.
 */
public class DResult extends DRef {
    private static Logger log = Logger.getLogger(DResult.class);

    TEnum<EnumError> errcode = new TEnum<>(EnumError.Error);
    TString errmsg = new TString();

    public DResult() {
        try {
            JsonFiletr filter = errcode.filter(JsonFiletr.class);
            filter.setGetCall(new FilterRef() {
                @Override
                public Object filter(Object object) throws Exception {
                    if (null == null)
                        return null;

                    if (object instanceof EnumError)
                        return ((EnumError) object).getErrode();

                    return object;
                }
            });

            filter.setSetCall(new FilterRef() {
                @Override
                public Object filter(Object object) throws Exception {
                    for (EnumError item : EnumError.values()) {
                        if (("" + item.getErrode()) == object)
                            return item;
                    }
                    return null;
                }
            });
        } catch (Exception e) {
            log.error(e);
        }
    }
}
